package valutatore;

import valutatore.TypeOp.Type;

public class BinaryExpr extends Expr {
	private Expr left;
	private Expr right;
	private Type oper;
	
	public BinaryExpr(Expr left, TypeOp.Type oper, Expr right) {
		this.left = left;
		this.oper = oper;
		this.right = right;
	}
		
	@Override
	public Value eval(Env env) {
		switch(oper) {
			case Plus: return left.eval(env).plus(right.eval(env));
			case Minus: return left.eval(env).minus(right.eval(env));
			case Times: return left.eval(env).times(right.eval(env));
			case Div: return left.eval(env).div(right.eval(env));
			case Mod: return left.eval(env).mod(right.eval(env));
			case LogAnd: return left.eval(env).logAnd(right.eval(env));
			case LogOr: return left.eval(env).logOr(right.eval(env));
			case Eq: return left.eval(env).eq(right.eval(env));
			case Not: return left.eval(env).not(right.eval(env));
			case Lt: return left.eval(env).lt(right.eval(env));
			case Le: return left.eval(env).le(right.eval(env));
			case Gt: return left.eval(env).gt(right.eval(env));
			case Ge: return left.eval(env).ge(right.eval(env));
			default: throw new RuntimeException("Unknown operation");
		}
	}
}
